package com.yg.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yg.user.mapper.UserMapper;
import com.yg.user.pojo.User;
import com.yg.user.pojo.vo.UserVo;
import com.yg.user.service.UserService;
import com.yg.util.JwtUtils;
import com.yg.util.Result;
import com.yg.util.StatusCode;
import jdk.net.SocketFlow;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author 魏成龙
 * @since 2020-11-07
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public Result login(UserVo userVo) {
        String phone = userVo.getPhone();
        String password = userVo.getPassword();
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("phone",phone);
        userQueryWrapper.eq("password",password);
        User user = baseMapper.selectOne(userQueryWrapper);
        if (user==null){
            return new Result(false, StatusCode.LOGINERROR,"用户名或密码错误");
        }
        String token = JwtUtils.getJwtToken(user.getId() + "", user.getNickName());
        return new Result(true,StatusCode.OK,"登录成功",token);
    }

}
